package springcloudeDemo;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * helloService
 *
 * @author Eric Wu
 * @date 2019-12-10
 * @since 1.8
 */
@Service
public class HelloService {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "helloFallback")
    public String helloService() {
        Long start = System.currentTimeMillis();
        String result = restTemplate
                .getForEntity("http://eureka-provider/index", String.class)
                .getBody()+"-hyrix";
        Long duration = System.currentTimeMillis() -start;
        System.out.println("DURATION: "+duration);
        return result;
    }

    public String helloFallback(){
        return "error";
    }

}
